package logic

import (
	"cart_srv/model/mysql"
	"context"
	"fmt"

	"cart_srv/cart"
	"cart_srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CartShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCartShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CartShowLogic {
	return &CartShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CartShowLogic) CartShow(in *cart.CartShowRequest) (*cart.CartShowResponse, error) {
	// todo: add your logic here and delete this line
	g := mysql.Good{}
	err := g.GetGood(int(in.Id))
	if err != nil {
		return nil, fmt.Errorf("查询失败")
	}
	return &cart.CartShowResponse{
		UserId:     int64(g.UserId),
		GoodTitle:  g.GoodTitle,
		GoodStock:  int64(g.GoodStock),
		GoodStatus: int64(g.GoodStatus),
		GoodPrice:  g.GoodPrice,
		Id:         int64(g.ID),
	}, nil
}
